from quote.db.db_handle import DbHandle


class DbCustomer:
    def __init__(self):
        self.db = DbHandle()

    def del_customer(self,customerNo):  #删除客户
        self.db.update_data("delete from tb_customer where customerNO='"+customerNo+"'")

    def add_customer(self,customerNo,addr,name,other='',phone='',man=''): #增加客户
        self.db.update_data("insert into tb_customer(customerNo,address,customerName,otherInfo,phone,relationman) "
                            "values('"+customerNo+"','"+addr+"','"+name+"','"+other+"','"+phone+"','"+man+"')")
        # w = "insert into tb_customer values('"+customerNo+"')"
        # print(w)
    def modify_customer(self,customerNo,info,new_info):  #修改客户
        self.db.update_data("update tb_customer set "+info+"='"+new_info+"' where customerNO='"+customerNo+"'")

    def search_customer(self,customerNo): #查询客户
        v = self.db.search_data("select * from tb_customer where customerNO='"+customerNo+"'")
        # return v
        w =list(v[0].values())
        w.sort()
        return w
#..................老师讲解.......................................................
    #查询多个客户
    def search_customers(self,cus_no_lst):
        res = self.db.search_data("select * from tb_customer where customerNO in"+str(cus_no_lst))
        print(res)  #第一种方式：通过传元组的形式实现一次查询多个客户

        # for cus_no in cus_no_lst: #第二种方式：通过循环的方式进行多次查询
        #     self.db.search_data("select * from tb_customer where customerNO='"+cus_no+"'")

# if __name__ == '__main__':
#     a = DbCustomer()
#     # a.search_customers(('01','02','001'))
# # #     a.del_customer('000')
# #     a.add_customer('10111','tianfu','Afei')
#     print(a.search_customer('00004446'))
    # a.modify_customer('001','customerName','江湖')
